<?php
/**
* This page is used to delete a comment.
* Deleting a page requires that the user be logged in and the owner of a
*       personal wiki page, or a member of a community.
*
* @package folio
* @param int $ident The ident of the comment to delete.
* @param int $page_ident The page to whom this comment belongs.
**/

    define("context", "folio_page_delete_comment");
    // Run includes
    require_once("../../../includes.php");
    require_once("../model/page.php");
    require_once("../model/comment.php");
    require_once("../redirect.php");
    global $CFG;

    $title = __gettext("Delete Page");

    $page_ident = intval( required_param('page_ident'));
    $ident = intval( required_param('ident'));
        $url = url;

    // Load Page information
    $page = folio_page::SelectWherePageIdent( $page_ident );
    if( !$page )
        trigger_error('You can not delete a page that does not exist.', E_USER_ERROR);

    $comment = folio_comment::SelectWhereIdent( $ident );
    if( !$comment )
        trigger_error('Unable to find comment in database.', E_USER_ERROR);

    // Test permissions.
    if( !$page->Permission('update') ) {
        // No permission.
        // User doesn't have permission to delete the page.
        $body = __gettext('You do not have permission to delete this comment. ' .
            'You must be logged in, be deleting your own wiki page, ' .
            'or be a member of the community owning this page.');
    } else {
        // Permission.
        $body = __gettext('Click the below button to delete this comment. ' .
            'You will not be able to undo this ' .
            'action, so please be absolutely sure!');

        $redirect = new folio_redirect;
        $redirect->redirect_url = "{$url}mod/folio/html/page_redirection.php?" .
            "page_ident={$page->page_ident}";
        $redirect = $redirect->html();

        $body = <<< END
<img src="{$CFG->wwwroot}mod/folio/image/page_delete.png"/><br>

<form method="post" name="elggform" action="{$url}mod/folio/ajax/comment_delete.php">
    {$body}
    {$redirect}
    <br/>
    <input type="hidden" name="ident" value="{$ident}" />
    <input type="submit" value="Delete" />
</form>
</div>

END;

    }

    header("Cache-control: private");
    $body = templates_draw(array(
                    'context' => 'contentholder',
                    'title' => $title,
                    'body' => $body
                ));
    echo templates_page_draw(array(
                    $title, $body
                ));
?>
